package org.example.component;

import org.example.enums.ProductOrderPayTypeEnum;
import org.example.vo.PayInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PayFactory {
    @Autowired
    private AlipayStrategy alipayStrategy;

    @Autowired
    private WechatPayStrategy wechatPayStrategy;

    /**
     * 创建支付，简单工厂模式
     */
    public String pay(PayInfoVO payInfoVO) {
        String payType = payInfoVO.getPayType();
        if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.ALIPAY.name())) {
            // 支付宝实现
            PayStrategyContext payStrategyContext = new PayStrategyContext(alipayStrategy);
            return payStrategyContext.executeUnifiedOrder(payInfoVO);
        } else if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.WECHAT.name())) {
            // 微信实现
            PayStrategyContext payStrategyContext = new PayStrategyContext(wechatPayStrategy);
            return payStrategyContext.executeUnifiedOrder(payInfoVO);
        }
        return "";
    }

    /**
     * 查询订单状态
     */
    public String queryPaySuccess(PayInfoVO payInfoVO) {
        String payType = payInfoVO.getPayType();
        if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.ALIPAY.name())) {
            // 支付宝实现
            PayStrategyContext payStrategyContext = new PayStrategyContext(alipayStrategy);
            return payStrategyContext.executeQueryPaySuccess(payInfoVO);
        } else if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.WECHAT.name())) {
            // 微信实现
            PayStrategyContext payStrategyContext = new PayStrategyContext(wechatPayStrategy);
            return payStrategyContext.executeQueryPaySuccess(payInfoVO);
        }
        return "";
    }
}
